package br.com.salaodebeleza.persistence;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.persistence.Query;

import br.com.salaodebeleza.domain.TbCalcularServicos;
import br.gov.frameworkdemoiselle.stereotype.PersistenceController;
import br.gov.frameworkdemoiselle.template.JPACrud;

@PersistenceController
public class TbCalcularServicosDAO extends JPACrud<TbCalcularServicos, Long> {

	private static final long serialVersionUID = 1L;
	
	public List<TbCalcularServicos> findByMenuJPQL(Date dtInicio, Date dtFim) {
		 
		SimpleDateFormat formatador = new SimpleDateFormat("yyyy-MM-dd");  
		String inicio = formatador.format(dtInicio);
		String fim = formatador.format(dtFim);  
		String select =  "SELECT calc "
				+ "FROM TbServicos serv, TbCalcularServicos calc,  TbFuncionario func "
				+ "WHERE calc.dtAgendamento BETWEEN '" + inicio + "' AND '" + fim + "'"
				+ " AND calc.tbFuncionario.id = func.id "
				+ " AND serv.id = calc.tbServico.id ";

		Query query = getEntityManager().createQuery(select);
		
		return query.getResultList();
	
	}
	

}
